﻿using System;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace MikroTransfer
{
    public class Logging
    {
        static Logging instance = null;
        private Logging()
        {
        }
        public static Logging GetLog
        {
            get
            {
                if (instance == null)
                    instance = new Logging();
                return instance;
            }
        }
        public string LogFile { get; set; }
        public void ErrorLog(Exception error)
        {
            if (string.IsNullOrEmpty(LogFile))
            {
                LogFile = Application.StartupPath + "\\hata.txt";
            }
            StringBuilder sb = new StringBuilder();
            sb.Append("Tarih        :" + DateTime.Now.ToShortDateString() + Environment.NewLine);
            sb.Append("Saat         :" + DateTime.Now.ToShortTimeString() + Environment.NewLine);
            sb.Append("Hata Mesajı  :" + error.Message + Environment.NewLine);
            sb.Append("Hata Kaynağı :" + error.Source + Environment.NewLine);
            sb.Append("-------------------------------------------------------------------------" + Environment.NewLine);
            System.Windows.Forms.MessageBox.Show(sb.ToString());
            StreamWriter sw = new StreamWriter(LogFile, true);
            sw.Write(sb.ToString());
            sw.Close();
        }
    }
}
